import os
import sys
import torch
import hydra
from omegaconf import DictConfig, OmegaConf

import o2_TPAMI_data_loader as data_loader
import o3_TPAMI_train as trainer 

from torch.utils.tensorboard import SummaryWriter
from utils.utils import set_global_seed, get_label_dict
import time
import numpy as np
import random
DEVICE = 'cuda:0'

@hydra.main(config_path="configs")
def pipeline(cfg: DictConfig) -> None:
    #train agent
    print(os.getcwd())
    set_global_seed(cfg.config_groups.exp_kwargs.seed)
    train_agent = getattr(trainer, cfg.config_groups.trainer['class'])(
        **cfg.config_groups.trainer.kwargs,
        **cfg.config_groups.SPL.kwargs,
        **cfg.config_groups.DSR.kwargs,
        **cfg.config_groups.SVD.kwargs
    )
    train_agent.train()
    
def set_global_seed(seed=None):
    if seed is None:
        seed = int(time.time())%4096
    np.random.seed(seed)    
    random.seed(seed)    
    torch.manual_seed(seed) #cpu    
    torch.cuda.manual_seed_all(seed)  #并行gpu 
    
if __name__ == '__main__':
    pipeline()
    